Skip to content

Support null-pointer without operand in interpreter #2917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

mgudemann
Copy link
Contributor

Before the interpreter evaluate function always expected a pointer type to have an operand, but we can have NULL pointers without operand, in the example it was from cprover_string_content

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: 624d1aa).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/84141522

@mgudemann mgudemann force-pushed the fix/interpreter/null_pointer_no_operand branch from 624d1aa to 8b3bfaa Compare September 7, 2018 15:29
@@ -339,11 +339,19 @@ void interpretert::evaluate(
evaluate(expr.op0(), dest);
return;
}
if(expr.has_operands() && !to_integer(expr.op0(), i))
else if(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, not being changed here, but as I'm trying to understand the code: line 334 suggests there is a type ID_address_of?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That surely must be in error!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this (and one other occurrence) I don't think those can be types

@@ -339,11 +339,19 @@ void interpretert::evaluate(
evaluate(expr.op0(), dest);
return;
}
if(expr.has_operands() && !to_integer(expr.op0(), i))
else if(
expr.has_operands() && !to_integer(to_constant_expr(expr.op0()), i))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does a pointer-typed constant (mind the test in line 300) with operands even look like?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constant memory offset? void *x = 0x100? Don't know if that is ever what you want

Copy link
Contributor Author

@mgudemann mgudemann Sep 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tautschnig this for example

java::@inflight_exception
constant
  * type: pointer
      * width: 64
      * #no_nondet_initialization: 1
      0: empty
  * value: 0000000000000000000000000000000000000000000000000000000000000000
  0: constant
      * type: pointer
          * width: 64
          * #no_nondet_initialization: 1
          0: empty
      * value: NULL

effectively this here was the culprit for the failed to evaluate expression: null:

cprover_string_content::cprover_string_content
constant
  * type: pointer
      * width: 64
      0: unsignedbv
          * width: 16
  * value: NULL
  * #source_location: 
    * file: org/apache/tika/parser/prt/PRTParser.java
    * line: 222
    * function: java::org.apache.tika.parser.prt.PRTParser.extractText:([BZ)Ljava/lang/String;
    * java_bytecode_index: 22
!! failed to evaluate expression: null

(both first name then .pretty output)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is definitely wrong (!) Could you raise a ticket either on issues here or on Jira to track this down. @LAJW I bet this is why you had some weird edge case handling code for null pointers!

// check if expression is constant null pointer without operands
else if(
!expr.has_operands() && !to_integer(to_constant_expr(expr), i) &&
i == 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might just do expr.is_zero(), although config.ansi_c.NULL_is_zero should actually be considered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made it i.is_zero() I am not sure that java correctly sets the NULL_is_zero in any case

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: 8b3bfaa).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/84148025

@mgudemann mgudemann force-pushed the fix/interpreter/null_pointer_no_operand branch from 8b3bfaa to 56ef1d4 Compare September 7, 2018 16:40
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: 56ef1d4).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/84153742

Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how feasible this is, but I have no idea what this change does so it'd be great to ad a (unit?) test.

@mgudemann mgudemann force-pushed the fix/interpreter/null_pointer_no_operand branch from 56ef1d4 to 55a1dfe Compare September 10, 2018 14:17
@mgudemann
Copy link
Contributor Author

@thk123 this fixes an error message from the interpreter. It should be possible to call the evaluate method f the interpreter and to check the result.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: 55a1dfe).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/84304603

@mgudemann mgudemann force-pushed the fix/interpreter/null_pointer_no_operand branch from 4524b08 to d7b43f2 Compare September 11, 2018 08:25
@smowton
Copy link
Contributor

smowton commented Sep 11, 2018

I don't have a strong opinion which one we want, but surely there should be one correct form of a null pointer constant, and the interpreter should understand that one form?

@tautschnig the "operand" form is I believe inspired by the constant object pointers produced by prop_convt::get, which will make something like 0x100 (operand &obj_xyz), thus providing both the address and the meaning of that address. The null with operands is giving the numerical representation (0) and the symbolic one (null).

@mgudemann mgudemann force-pushed the fix/interpreter/null_pointer_no_operand branch 2 times, most recently from b684a94 to bce73d4 Compare September 11, 2018 09:26
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR failed Diffblue compatibility checks (cbmc commit: bce73d4).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/84403064
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

@thk123
Copy link
Contributor

thk123 commented Sep 11, 2018

@smowton - thanks for this that makes sense. But null_pointer_exprt returns the no-operand version - so it should be updated to return this op'd version if this is really is the "correct" format for a pointer. This should also be documented (perhaps in pointer_typet/null_pointer_exprt/address_of_exprt)

Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test!

💡 can we get one for the other kind of null pointer too?
🚫 avoid putting code only required for test in the main src

@@ -306,6 +306,14 @@ class interpretert:public messaget

void initialize(bool init);
void show_state();

friend mp_vectort
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 This is required for the unit test right? I think it is cleaner to declare friend class interpreter_testt and then put this into the unit folder 0 as it stands you might as well make evaluate public no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will go with the friend class, that is hopefully less controversial

interpretert::mp_vectort mp_vector =
interpreter_evaluate(interpreter, constant_expr);

REQUIRE(mp_vector.size() == 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ You can use

REQUIRE_THAT(mp_vector, Catch::Matchers::Vector::Equals<mp_integer>{{0}});

To check that the array is exactly {0}

@smowton
Copy link
Contributor

smowton commented Sep 11, 2018

It might be better to say there is a correct format in a particular place. The interpreter operates over traces, which have been produced by prop_convt::get'ing all the symbols in a particular equation. My guess is it's behaving differently for constants given in the input equation vs. symbols that have been solved for a zero / null value.

@mgudemann mgudemann force-pushed the fix/interpreter/null_pointer_no_operand branch from bce73d4 to d4f9fb0 Compare September 11, 2018 12:24
@mgudemann
Copy link
Contributor Author

@thk123 addressed your comments

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR failed Diffblue compatibility checks (cbmc commit: d4f9fb0).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/84421606
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

@mgudemann mgudemann force-pushed the fix/interpreter/null_pointer_no_operand branch from d4f9fb0 to d22f26a Compare September 11, 2018 14:47
@@ -339,7 +339,16 @@ void interpretert::evaluate(
evaluate(expr.op0(), dest);
return;
}
if(expr.has_operands() && !to_integer(expr.op0(), i))
else if(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all of the if/else if return, you can make them all ifs.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: d22f26a).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/84449831

Result was moved twice instead of initializing `input` field with the
given `input`.
@mgudemann mgudemann force-pushed the fix/interpreter/null_pointer_no_operand branch from d22f26a to 7bc468d Compare September 12, 2018 09:41
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: 7bc468d).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/84545908

@mgudemann mgudemann force-pushed the fix/interpreter/null_pointer_no_operand branch from 7bc468d to f7e9715 Compare September 12, 2018 12:04
@mgudemann
Copy link
Contributor Author

based on #2935

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed Diffblue compatibility checks (cbmc commit: f7e9715).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/84558263

@mgudemann mgudemann merged commit 8863b9c into diffblue:develop Sep 13, 2018
@mgudemann mgudemann deleted the fix/interpreter/null_pointer_no_operand branch September 13, 2018 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants